package gold.digger;

import gold.vo.ListNode;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC203 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public ListNode removeElements(ListNode head, int val) {
            while (null != head && head.val == val) head = head.next;
            if (null == head) return null;
            ListNode cur = head.next, pre = head;
            while (cur != null) {
                while (null != cur && val == cur.val) cur = cur.next;
                pre.next = cur;
                pre = cur;
                if (null == cur) break;
                cur = cur.next;
            }

            return head;
        }
    }

    public void run() {
        Solution solution = new Solution();
        ListNode root = ListNode.createList("6->6->6");
        System.out.println(solution.removeElements(root, 6));
    }

    public static void main(String[] args) throws Exception {
        LC203 an = new LC203();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
